package com.gome.ocean.controller.authority;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.Page;
import com.gome.ocean.common.utils.ResponsePage;
import com.gome.ocean.dao.model.authority.UserOptLogBO;
import com.gome.ocean.service.authority.IUserOptLogService;
import com.gome.ocean.service.base.AuthorityBaseController;
import com.google.common.collect.Maps;

/**
 * 
 * 用于查询 日志记录信息
 * @author zhangguoqing
 */
@Controller
@RequestMapping("/dataxlog")
public class OptLogController extends AuthorityBaseController{
	
	@Autowired
	private IUserOptLogService userOptLogService;
	
	@RequestMapping(value = "/tofindlog" , method = RequestMethod.GET)
	public ModelAndView getOptLog(ModelAndView mav,HttpServletRequest request){
		mav.setViewName("optlog/optlog-find");
		return mav;
	}
	
	@RequestMapping(value = "/tofindparam" , method = RequestMethod.POST)
	@ResponseBody
	public ResponsePage findLogInfo(HttpServletRequest request){
		ResponsePage res = new ResponsePage();
		try {
			String email = request.getParameter("email");
			String startTime = request.getParameter("startTime");
			String endTime = request.getParameter("endTime");
			Integer pageNum = getPageNum();
			Integer pageSize = getPageSize();
			Map<String, Object> map = Maps.newHashMap();
			map.put("email", email);
			map.put("startTime", startTime);
			map.put("endTime", endTime);
			Page<UserOptLogBO> page = userOptLogService.getUserOptLogAllInfo(pageNum, pageSize, map);
			if (page == null) {
				return res.setErrorMsg("email未填写，查询失败！");
			}
			return res.setPage(page, "查询成功");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res.setErrorMsg("查询失败");
	}
	
}
